<?php
/**
 * XueYuan Project
 *
 * @package	XueYuan 
 * @author	Jiuchi Team
 * @since	Version 1.0.0
 * @filesource
 */
defined('BASEPATH') OR exit('No direct script access allowed');
/**
 * User concern model class
 * @author Wayne Yu
 */
class User_dynamic_model extends Jiuchi_Model{
	/**
	 * Construct function
	 */
	public function __construct() {
		parent::__construct();
		$this->table = 'user_dynamic';
	}
	
	/**
	 * Get users' Dynamic
	 * @param int $cid:Circle Id
	 * @param int $pageSize:Page Size
	 * @param int $last Item
	 */
	public function getDynamic($userList, $pageSize = 0, $lastItem = 0){
		$count = -1;
		return $this->retrieve($count, $pageSize, $lastItem, NULL, NULL, 'created_at', 'DESC', array('user_id' => $userList), array());
	}

	public function getTimeFormat($btime){
		$result = '';
		$time =time() - $btime ;
		if($time < 60){
			$result = $time.'秒前';
		} else if($time < 1800){
			$result = floor($time/60).'分钟前';
		} else if($time < 3600){
			$result = '半小时前';
		} else if($time < 86400){
			$result = floor($time/3600).'小时前';
		} else{
			$zt = strtotime(date('Y-m-d 00:00:00'));
			$qt = strtotime(date('Y-m-d 00:00:00',strtotime("-1 day")));
			$st = strtotime(date('Y-m-d 00:00:00',strtotime("-2 day")));
			$bt = strtotime(date('Y-m-d 00:00:00',strtotime("-7 day")));
			if($btime < $bt){
				$result = date('Y-m-d', $btime);
			} else if($btime < $st){
				$result = floor($time/86400).'天前';
			} else if($btime < $qt){
				$result = "前天".date('H:i', $btime);
			} else{
				$result = '昨天'.date('H:i', $btime);
			}
		}
		return $result;
	}
}